<?php
header("Cache-Control: no-cache, must-revalidate");
    $name=$_GET["name"];
    $con = mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("tubetogether", $con);
    $sql="SELECT * FROM names WHERE Name = '$name' AND LoggedIn = 1";
    $result = mysql_query($sql);

    if (mysql_fetch_array($result)) {
        $sql="UPDATE names SET LoggedIn=0 WHERE Name = '$name'";
        mysql_query($sql);
        $message="OK";
    } else {
        $message="ERROR";
    }

    $sql="DELETE FROM messages WHERE Reciever='$name'";
    mysql_query($sql);
    mysql_close($con);
    echo "<?xml version=\"1.0\"?>\n";
    echo "<leave>";
    echo $message;
    echo "</leave>\n";
?>
